
/**
 *	\file
 *	Declares the sun_entry_point function.
 *	\author Sean Tromans
 */

#include <sun_pre_compiled.hpp>
#include <sun/entry_point/user_entry_point.hpp>
#include <sun/internal/system.hpp>

#if	!defined(WIN32)
#error This file should only be built on windows.
#endif

#include <windows.h>
#include <vector>

SUN_PUSH_DISABLE_PROGRAM_OPTIONS_WARNINGS( )
#include <boost/program_options.hpp>
SUN_POP_DISABLED_WARNINGS( )

#if ( defined(_DEBUG) || defined(DEBUG) )
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif

int WINAPI WinMain(	HINSTANCE	instance_handle,
					HINSTANCE	previous_instance_handle,
					LPSTR		command_line,
					int			command_show	)
{
	sun::system_config::create_singleton( );

#if ( defined(_DEBUG) || defined(DEBUG) )
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	//_CrtSetBreakAlloc(167);
#endif

	sun::system_config::get_singleton( )->add_param<HINSTANCE>( "instance_handle",			instance_handle );
	sun::system_config::get_singleton( )->add_param<HINSTANCE>( "previous_instance_handle", previous_instance_handle );
	sun::system_config::get_singleton( )->add_param<int>(		"command_show",				command_show );

	sun::command_line_type const arguments = boost::program_options::split_winmain( command_line );

	sun::system_config::get_singleton( )->add_param<sun::command_line_type>( "command_line", arguments );
	int out = sun_entry_point( arguments );

	sun::system_config::destroy_singleton( );

	return out;
}
